﻿
Partial Class webservices_baycity
    Inherits System.Web.UI.Page

    Public ReadOnly Property Search As String
        Get
            Return CWeb.RequestStr("search")
        End Get
    End Property
    Public ReadOnly Property TranscriptsOnly As Boolean
        Get
            Return CWeb.RequestBool("transcriptsOnly")
        End Get
    End Property


    Protected Sub webservices_baycity_Init(sender As Object, e As System.EventArgs) Handles Me.Init
        txtSearch.Text = Search
        chkTrans.Checked = TranscriptsOnly

        lnkPodcast.NavigateUrl = CSitemap.External_Podcast
        lnkVideos.NavigateUrl = CSitemap.Video(Nothing, 0)
        lnkEpub.NavigateUrl = CSitemap.Ebooks_(Nothing, 0)
        lnkSermons.NavigateUrl = CSitemap.Sermons_(Nothing, 0, 0)
        lnkNotes.NavigateUrl = CSitemap.Notes_(Nothing, 0)
    End Sub
    Protected Sub webservices_baycity_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        Dim results As CProductList = CProduct.Cache.Active.Sermons.GetByLocationId(ELocation.Baycity).Search(Search)
        'Dim lyn As CProductList = CProduct.Cache.GetByIsActive(False).GetBySpeakerId(26)
        'Dim join As CProductList = results
        'If lyn.Count > 0 Then
        '    join = New CProductList(results.Count + lyn.Count)
        '    join.AddRange(results)
        '    join.AddRange(lyn)
        '    join.Sort()
        'End If
        'results = join

        If TranscriptsOnly Then
            results = results.HavingTranscripts
        Else
            results = results.HavingMp3
        End If
        results = results.SortByCreatedDescName()

        lblNoResults.Visible = (results.Count = 0)

        For Each i As CProduct In ctrlPaging.Display(results)
            UCBaycity(plh).Display(i)
        Next

        Dim limit As Integer = 16
        For Each i As CProduct In CProduct.Cache.Active.ConferenceSets
            If String.IsNullOrEmpty(i.ProductTiny) Then Continue For
            If 1438 = i.ProductId Then Continue For '5seconds - image is the wrong size/shape
            Dim lnk As New HyperLink
            lnk.ImageUrl = CSitemap.ProductTiny(i)
            lnk.ToolTip = i.ProductNameAndContents
            lnk.NavigateUrl = CSitemap.Decide(i)
            lnk.Target = "_blank"
            lnk.Style.Add("padding", "3px 3px")
            plhThumbs.Controls.Add(lnk)
            If plhThumbs.Controls.Count = limit Then Exit For
        Next

        Dim chin As CLanguage = CLanguage.Cache.GetById(ELanguage.Chinese)
        'lnkChinese.Text = chin.NativeAndName & "&raquo;"
        lnkChinese.NavigateUrl = CSitemap.Sermons(Nothing, 0, ELanguage.Chinese)

    End Sub



#Region "User Controls"
    Private Shared Function UCBaycity(ByVal target As Control) As webservices_usercontrols_UCBaycity
        Dim ctrl As Control = target.Page.LoadControl("~/webservices/usercontrols/ucbaycity.ascx")
        target.Controls.Add(ctrl)
        Return CType(ctrl, webservices_usercontrols_UCBaycity)
    End Function
#End Region

    Protected Sub btnSearch_Click(sender As Object, e As System.EventArgs) Handles btnSearch.Click, chkTrans.CheckedChanged
        Dim url As String = String.Concat("baycity.aspx?search=", HttpUtility.UrlEncode(txtSearch.Text))
        If chkTrans.Checked Then url = String.Concat(url, "&transcriptsOnly=true")
        Response.Redirect(url, True)
    End Sub
End Class
